[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
getenv() Get a Value from the Environment Table
#include <stdlib.h>
char *getenv(varname);
const char *varname; Name of environment variable
getenv() searches the list of environment variables for an entry
corresponding to 'varname'.
Returns: A pointer to the environment table entry containing
the current string value of the variable associated
with 'varname'. NULL is returned if 'varname' is not
currently defined.
Notes: Entries can be changed using putenv(). Use strdup()
or strcpy() to make a copy of the string to modify
the returned value without affecting the environment
table.
-------------------------------- Example ---------------------------------
The following statements get some environment settings and print them
out.
#include <stdlib.h>
char *pathvar, *libvar;
main()
{
pathvar = getenv("PATH"); /* NULL if no PATH */
libvar = getenv("LIB"); /* NULL if no LIB setting */
printf("PATH AND LIB ENVIRONMENT SETTINGS\n");
printf("\tPATH: %s\n",pathvar);
printf("\tLIBRARY: %s\n",inclvar);
}
See Also:
putenv()
strdup()
strcpy()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson